package sessionbean.facade;

import entity.AccountGroup;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class AccountGroupFacade extends AbstractFacade<AccountGroup> {
    @PersistenceContext(unitName = "AmazonWishlistTrackerPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AccountGroupFacade() {
        super(AccountGroup.class);
    }
    
    public AccountGroup findByName(String name) {
        AccountGroup group = null;
        
        Query query = getEntityManager().createNamedQuery("AccountGroup.findByName");
        query.setParameter("name", name);
        
        try {
            group = (AccountGroup) query.getSingleResult();
        } catch(NoResultException exception) {
            
        }
        
        return group;
    }
}